#include <stdio.h>


void QuickSort(int *arr, int n);
void Swap(int  *a , int *b);
int main()
{
    int a[] = {8,3,10,9,11,14,7,6,20,18,17,65,13,19,18};
    printf("排序前");
    for (int i = 0; i < 15; i++)
    {
        printf("%d,",  a[i]);
        
    }
    printf("\n");
    QuickSort(a, 15);
    printf("\n排序后");
    for (int i = 0; i < 15; i++)
    {
        printf("%d,",  a[i]);
        
    }
    printf("\n");
    return 0;
}

/**
  *@param  待排序的数组
  *@param  数组元素个数
 */
void QuickSort(int *arr, int n){
    if(arr==NULL || n < 2){
        return;
    }
    int i,j;
    int tmp;
    i = 0; 
    j = n-1;
    tmp = arr[0];
    while (i!=j)
    {
        while( i != j && arr[j] >= tmp ){
            j--;
        }
        if(i == j)
            break;
        Swap(arr+i, arr+j);
        while( i != j && arr[i] <= tmp ){
            i++;
        }
        if(i == j)
           break;    
        Swap(arr+i, arr+j);  
    }
    printf("i=%d,j=%d,n=%d\n",i,j,n);
    QuickSort(arr, i); //递归排序左边
    if(i<n-1){
        QuickSort(arr+i+1, n-i-1);//递归排序右边
    }
    
}







